package name.huzhenbo.java.patterns.flyweight;

import java.util.HashMap;
import java.util.Map;

class GlyphFactory {
    private static final Map<Character, GlyphCharacter> glyphCharacters = new HashMap<Character, GlyphCharacter>();

    public Glyph createRow(int i) {
        return new GlyphRow(i);
    }

    public Glyph createColumn(int i) {
        return new GlyphColumn(i);
    }

    public Glyph createCharacter(char c) {
        GlyphCharacter glyphCharacter = glyphCharacters.get(c);
        if (glyphCharacter == null) {
            GlyphCharacter newCharacter = new GlyphCharacter(c);
            glyphCharacters.put(c, newCharacter);
            return newCharacter;
        }
        return glyphCharacter;
    }
}
